package com.apartment.own.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.apartment.common.utils.DateUtils;
import com.apartment.common.utils.mp.SelectBuilder;
import com.apartment.own.mapper.CommonMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.apartment.own.mapper.OwnResHouseContractMapper;
import com.apartment.own.domain.OwnResHouseContract;
import com.apartment.own.service.IOwnResHouseContractService;

import javax.servlet.ServletSecurityElement;

/**
 * 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租Service业务层处理
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@Service
public class OwnResHouseContractServiceImpl extends ServiceImpl<OwnResHouseContractMapper,OwnResHouseContract> implements IOwnResHouseContractService
{
    @Autowired
    private OwnResHouseContractMapper ownResHouseContractMapper;
    @Autowired
    private CommonMapper commonMapper;
    /**
     * 查询合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * 
     * @param id 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租ID
     * @return 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     */
    @Override
    public OwnResHouseContract selectOwnResHouseContractById(Long id)
    {
        return ownResHouseContractMapper.selectOwnResHouseContractById(id);
    }

    /**
     * 查询合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租列表
     * 
     * @param ownResHouseContract 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * @return 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     */
    @Override
    public List<OwnResHouseContract> selectOwnResHouseContractList(OwnResHouseContract ownResHouseContract)
    {
        return ownResHouseContractMapper.selectOwnResHouseContractList(ownResHouseContract);
    }

    /**
     * 新增合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * 
     * @param ownResHouseContract 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * @return 结果
     */
    @Override
    public int insertOwnResHouseContract(OwnResHouseContract ownResHouseContract)
    {
        ownResHouseContract.setCreateTime(DateUtils.getNowDate());
        return ownResHouseContractMapper.insertOwnResHouseContract(ownResHouseContract);
    }

    /**
     * 修改合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * 
     * @param ownResHouseContract 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * @return 结果
     */
    @Override
    public int updateOwnResHouseContract(OwnResHouseContract ownResHouseContract)
    {
        ownResHouseContract.setUpdateTime(DateUtils.getNowDate());
        return ownResHouseContractMapper.updateOwnResHouseContract(ownResHouseContract);
    }

    /**
     * 批量删除合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     * 
     * @param ids 需要删除的合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租ID
     * @return 结果
     */
    @Override
    public int deleteOwnResHouseContractByIds(Long[] ids)
    {
        return ownResHouseContractMapper.deleteOwnResHouseContractByIds(ids);
    }

    /**
     * 删除合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租信息
     * 
     * @param id 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租ID
     * @return 结果
     */
    @Override
    public int deleteOwnResHouseContractById(Long id)
    {
        return ownResHouseContractMapper.deleteOwnResHouseContractById(id);
    }

    @Override
    public Map contractInfoByResId(String id) {
        List<Map> maps = commonMapper.listHouseAndFeeSelectBuilder(
                new SelectBuilder()
                        .append(SelectBuilder.PropertyFunctionEnum.ALL,"contract",null,null)
                        //.append(SelectBuilder.PropertyFunctionEnum.ALL,"house",null,null)
                ,new QueryWrapper<OwnResHouseContract>()
                        .eq("house.id",id)
        );
        return (maps == null||maps.size() == 0 )? null :maps.get(0);
    }

}
